package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.IcUser;
import com.ruoyi.system.service.IIcUserService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 微信用户Controller
 * 
 * @author ruoyi
 * @date 2024-07-01
 */
@Controller
@RequestMapping("/system/icUser")
public class IcUserController extends BaseController
{
    private String prefix = "system/icUser";

    @Autowired
    private IIcUserService icUserService;

    @RequiresPermissions("system:icUser:view")
    @GetMapping()
    public String icUser()
    {
        return prefix + "/icUser";
    }

    /**
     * 查询微信用户列表
     */
    @RequiresPermissions("system:icUser:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(IcUser icUser)
    {
        startPage();
        List<IcUser> list = icUserService.selectIcUserList(icUser);
        return getDataTable(list);
    }

    /**
     * 导出微信用户列表
     */
    @RequiresPermissions("system:icUser:export")
    @Log(title = "微信用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(IcUser icUser)
    {
        List<IcUser> list = icUserService.selectIcUserList(icUser);
        ExcelUtil<IcUser> util = new ExcelUtil<IcUser>(IcUser.class);
        return util.exportExcel(list, "微信用户数据");
    }

    /**
     * 新增微信用户
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存微信用户
     */
    @RequiresPermissions("system:icUser:add")
    @Log(title = "微信用户", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(IcUser icUser)
    {
        return toAjax(icUserService.insertIcUser(icUser));
    }

    /**
     * 修改微信用户
     */
    @RequiresPermissions("system:icUser:edit")
    @GetMapping("/edit/{iuId}")
    public String edit(@PathVariable("iuId") Long iuId, ModelMap mmap)
    {
        IcUser icUser = icUserService.selectIcUserByIuId(iuId);
        mmap.put("icUser", icUser);
        return prefix + "/edit";
    }

    /**
     * 修改保存微信用户
     */
    @RequiresPermissions("system:icUser:edit")
    @Log(title = "微信用户", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(IcUser icUser)
    {
        return toAjax(icUserService.updateIcUser(icUser));
    }

    /**
     * 删除微信用户
     */
    @RequiresPermissions("system:icUser:remove")
    @Log(title = "微信用户", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(icUserService.deleteIcUserByIuIds(ids));
    }
}
